<?php
namespace App\Modules\Admin\Services;

use App\Models\Admin\SysMenu;
use Illuminate\Support\Facades\Auth;

class MenuService extends AdminService
{
    protected $model = SysMenu::class;

    public function getRoutes()
    {
        $user = Auth::user();
        return $user->sysRoles->map(function($role) {
            return $role->permissions;
        })->collapse();

    }

    public function getQueryBuilder(Array $data)
    {
        $queryBuilder = SysMenu::query();

        // dd($queryBuilder);
        if(isset($data['name']) && strlen($data['name']) > 0) {
            $this->queryBuilder = $queryBuilder->where('name', $data['name']);
        }

        $this->queryBuilder = $queryBuilder->with(['children'])->whereNull('parent_id')->orderBy('id', 'desc');
    }
}